layui.define(['layer', 'jquery', 'laytpl'], function (exports) {
  var $ = layui.$,
      layer = layui.layer,
      laytpl = layui.laytpl,
      id;

  var worksDetail = {
    init: function () {
      id = Util.getQueryString('id');
      $.get('/admin/works/getWorksVoById', {id: id}, function (result) {
        var getTpl = $('#content').html(),
            body = $("body");
        laytpl(getTpl).render(result, function (html) {
          body.html(html);
        });
      }, 'json')
    },
    bindEvent: function () {
      $(document).on('click','.pass-btn',function () {
        layer.confirm('确定要审核通过?', {icon: 3, title: '提示'},
            function (index) {
              var loadingIndex = layer.load();
              $.post("/admin/works/pass",{id:id},function (result) {
                layer.close(loadingIndex);
                if(result.success){
                  layer.msg("审核成功！")
                }else{
                  layer.msg("审核失败，失败原因："+result.message);
                }
              },'json')

              layer.close(index);
            });
      });

      $(document).on('click','.refuse-btn',function () {
        layer.confirm('确定要拒绝？',{icon:3, title: '提示'},function (index) {
          var refuseReason = $('#refuseDesc').val();
          if (!refuseReason) {
            layer.msg('请输入拒绝原因')
            return false;
          }
          var loadingIndex = layer.load();
          $.post("/admin/works/refuse", {id: id, refuseReason: refuseReason},
              function (result) {
                layer.close(loadingIndex);
                if (result.success) {
                  layer.msg("审核成功！")
                } else {
                  layer.msg("审核失败，失败原因：" + result.message);
                }
              })
        })


      })
    }
  }
  worksDetail.init();
  worksDetail.bindEvent();
  exports('worksdetail', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
})